//===============================================================================
// Microsoft patterns & practices
// Web Client Software Factory
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Practices.CompositeWeb;
using Microsoft.Practices.CompositeWeb.Services;
using Microsoft.Practices.CompositeWeb.Interfaces;
using WCSFContrib.ECommerceCatalog.Product.Tests.Mocks;

namespace WCSFContrib.ECommerceCatalog.Product.Tests
{
    /// <summary>
    /// Summary description for ProductModuleInitializerFixture
    /// </summary>
    [TestClass]
    public class ProductModuleControllerFixture
    {
        public ProductModuleControllerFixture()
        {
        }

        [TestMethod]
        public void ShouldGetProduct()
        {
            TestableProductController controller = GetProductControllerInitialized();

            controller.GetProduct(0);

            Assert.IsTrue(controller.MockItemService.GetItemByIdCalled);
        }

        [TestMethod]
        public void ShouldSearchProducts()
        {
            TestableProductController controller = GetProductControllerInitialized();

            controller.SearchProducts("");

            Assert.IsTrue(controller.MockItemService.SearchItemsCalled);
        }

        [TestMethod]
        public void ShouldGoCartPage()
        {
            TestableProductController controller = GetProductControllerInitialized();

            controller.GoCartPage();

            Assert.IsTrue(controller.MockNavigationService.CartCalled);
        }

        [TestMethod]
        public void ShouldAddProductToCart()
        {
            TestableProductController controller = GetProductControllerInitialized();

            controller.AddProductToCart("", 0, 0);

            Assert.IsTrue(controller.MockCartService.AddItemCalled);
        }

        private TestableProductController GetProductControllerInitialized()
        {
            TestableProductController controller = new TestableProductController();

            return controller;
        }
    }

    public class TestableProductController : ProductController
    {
        public TestableProductController()
            : base(new MockItemService(), new MockCategoriesService(), new MockCartService(), new MockNavigationSevice())
        {
        }

        public MockItemService MockItemService
        {
            get { return this.ItemsService as MockItemService; }
        }

        public MockCategoriesService MockCategoriesService
        {
            get { return this.CategoriesService as MockCategoriesService; }
        }

        public MockCartService MockCartService
        {
            get { return this.CartService as MockCartService; }
        }

        public MockNavigationSevice MockNavigationService
        {
            get { return this.NavigationService as MockNavigationSevice; }
        }
    }
}